package operate.node;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.data.Stat;

import java.nio.charset.StandardCharsets;

/**
 * @author m0v1
 * @date 2021年09月07日 9:38 下午
 */
public class UpdateNode extends AbstractNodeOperation{
    @Override
    public void process(WatchedEvent event) {
        try {
            String path = "/zk-permanent-node";
            byte[] oldData = zooKeeper.getData(path, false, null);
            System.out.println("old data is " + new String(oldData));
            Stat stat = zooKeeper.setData(path, "this is new data".getBytes(StandardCharsets.UTF_8), -1);
            byte[] newData = zooKeeper.getData(path, false, null);
            System.out.println("new data is " + new String(newData));
        } catch (KeeperException | InterruptedException e) {
            e.printStackTrace();
        }

    }
}
